package com.aoxin.service.impl.course.webCourse;

import java.util.List;

import com.aoxin.mapper.opm.SlfEmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.aoxin.mapper.SlfVideoMapper;
import com.aoxin.model.SlfVideo;
import com.aoxin.service.inter.course.webCourse.VideoService;
import com.aoxin.util.EmptyUtil;
import com.aoxin.util.ErrorUtil;
import com.aoxin.util.ThreadLocalUtil;

@Service
public class VideoServiceImpl implements VideoService {

    @Autowired
    SlfVideoMapper slfVideoMapper;

    @Autowired
    private SlfEmployeeMapper slfEmployeeMapper;

    @Override
    @Transactional
    public Integer deleteVideo(Integer videoId) {
        Integer result = 0;
        if(videoId != null){
            result = slfVideoMapper.deleteVideo(videoId);
        }
        return result;
    }

    @Override
    @Transactional
    public Integer deleteVideos(List<Integer> videoIds) {
        Integer result = 0;
        if(videoIds != null && videoIds.size()>0){
            result = slfVideoMapper.deleteVideos(videoIds);
        }
        return result;
    }

    @Override
    @Transactional
    public Integer insertVideo(SlfVideo slfVideo) throws IllegalAccessException {
        Integer result = 0;
        if(!EmptyUtil.objFieldsIsEmpty(slfVideo)){
            slfVideo.setName(slfVideo.getTitle());
            slfVideo.setEmployeeId(ThreadLocalUtil.getEmployee().getEmployeeId());
            result = slfVideoMapper.insertVideo(slfVideo);
        }
        return result;
    }

    @Override
    public List<SlfVideo> getVideo(SlfVideo slfVideo) {
        List<SlfVideo> slfVideoList = slfVideoMapper.getVideo(slfVideo);
        for(SlfVideo slfVideo1:slfVideoList){
            String name = this.slfEmployeeMapper.selectByPrimaryKey(slfVideo1.getEmployeeId()).getName();
            slfVideo1.setEmployeeName(name);
        }
        return slfVideoList;
    }

    @Override
    @Transactional
    public Integer updateVideo(SlfVideo slfVideo) throws IllegalAccessException {
        Integer result = 0;
        if(!EmptyUtil.objFieldsIsEmpty(slfVideo)){
            result = slfVideoMapper.updateVideo(slfVideo);
        }
        return result;
    }

    @Override
    public List<SlfVideo> displayVideo(SlfVideo slfVideo) {
        Assert.notNull(slfVideo,String.format(ErrorUtil.SLFACTIVITYRULE,"slfVideo"));
        List<SlfVideo> list=slfVideoMapper.displayVideo(slfVideo);
        return list;
    }
}
